<?php namespace system\model;
use houdunwang\model\Model;
class Link extends Model{
	//数据表
	protected $table = "link";

	//允许填充字段
	protected $allowFill = ['*' ];

	//禁止填充字段
	protected $denyFill = [ ];

	//自动验证
	protected $validate=[
		//['字段名','验证方法','提示信息',验证条件,验证时间]
	   ['lname','isnull','链接名字不能为空',3,3],
	   ['logo','isnull','网站logo不能为空',3,3],
	   ['url','isnull','链接地址不能为空',3,3],
	   ['sort','isnull','排序不能为空',3,3],
	];

	//自动完成
	protected $auto=[
		//['字段名','处理方法','方法类型',验证条件,验证时机]
		['addtime','time','function',self::MUST_AUTO,self::MODEL_BOTH],
	];
	//添加链接
	public function store(){
//	   p($_POST);
	   $this->save($_POST);
	}
	public function edit(){
	   $lid=$_POST['lid'];
	   $linkModel=$this->find($lid);
//	   p($linkModel);
	   $linkModel->lname=$_POST['lname'];
	   $linkModel->logo=$_POST['logo'];
	   $linkModel->url=$_POST['url'];
	   $linkModel->sort=$_POST['sort'];
	   $linkModel->save();
	   return ['valid'=>1,'message'=>'操作成功'];
	}

}